// -----------------------------------------------------------------------------
//
// Work is licensed by Arthur Fermi (C)2008-2011,
// under Creative Commons Attribution-Share Alike 3.0 Unported License
// To receive a copy of this license please visit
// http://creativecommons.org/licenses/by-sa/3.0/
//
// You are free to copy, distribute, transmit and adapt the work
// under the following conditions:
//
// You must attribute the work in the manner specified by the 
// author(s) or licensor (but not in any way that suggests that 
// they endorse you or your use of the work). 
//
// If you alter, transform, or build upon this work in any way,
// you may distribute the resulting work only under the same or 
// similar license to this one. 
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See points (6) and (7) of the license for more details.
//
// -----------------------------------------------------------------------------

// SimNet - Relay

// -----------------------------------------------------------------------------

// Enter the URL to your SimNet system, make sure to include the last /
// This will likely be http://<my-domain.com>/simnet/
string  gstrURL = "http://yourwebsite/simnet/";   

// Enter in the relay link channel, it is used in a whisper to communicate to the prim on the other sim.
integer gintRelay = -23456;   // Relay comms

// -----------------------------------------------------------------------------
// Do not change anything below here or you will likely break something
// -----------------------------------------------------------------------------
// compile with lsl2
// -----------------------------------------------------------------------------

string  gstrHTTP;
integer gintParcelComm1;  // Comm Channel used by SimNet

default
{
    state_entry()
    {
        gstrHTTP = llHTTPRequest(gstrURL + "simnet_toolbar.cn",[HTTP_METHOD, "POST"], ""); 
    }

    listen(integer channel, string name, key id, string message)
    {
        if (channel == gintParcelComm1)
        {
            llWhisper(gintRelay, message);
        }
        else if (channel == gintRelay)
        {
            llRegionSay(gintParcelComm1, message);
        }
    }

    http_response(key request_id, integer status, list metadata, string body)
    {
        if (request_id == gstrHTTP)
        {
            // get Variable to build the string
            gintParcelComm1 =  (integer)body;  
 
            // Link Listens
            llListen(gintRelay, "", NULL_KEY, ""); 
            
            // Device Listens
            gintParcelComm1 = (gintParcelComm1 * 7) / 3;          
            llListen(gintParcelComm1, "", NULL_KEY, "");
       }
    }
}


